package carmesi.wizards;

import java.util.Map;
import org.netbeans.api.java.project.JavaProjectConstants;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.SourceGroup;
import org.netbeans.api.project.Sources;
import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates;
import org.netbeans.spi.project.ui.templates.support.Templates;
import org.openide.WizardDescriptor.Panel;

/**
 *
 * @author Victor
 */
public class BeforeURLWizardIterator extends CarmesiWizardIterator implements ComponentValidator<BeforeURLComponent> {
    private BeforeURLComponent component;

    @Override
    protected Panel[] createPanels() {
        component=new BeforeURLComponent(getWizardDescriptor());
        component.setComponentValidator(this);
        Project project = Templates.getProject(getWizardDescriptor());
        Sources sources = (Sources) project.getLookup().lookup(Sources.class);
        SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        return new Panel[]{JavaTemplates.createPackageChooser(project, groups, component)};
    }

    @Override
    protected void setTemplateArguments(Map<String, String> args) {
        args.put("beforeURL", component.getBeforeURLValue().trim());
    }

    @Override
    public void validate(BeforeURLComponent panel) {
        if(component.getBeforeURLValue().trim().equals("")){
            throw new IllegalArgumentException("URL must not be empty");
        }
    }
    
}
